#include <QtGui/QApplication>
#include"MainWindow.h"
#include"graphe.h"
#include "biparti.h"
#include<iostream>

using namespace std;
#include<stdio.h>
#include <string>


int coloration(Biparti * g){

    while (1){
    cout<<endl;
    g->initialisationCouleur(0);
    cout<<"0 : Coloration sequentielle"<<endl;
    cout<<"1 : Coloration minimale"<<endl;
    cout<<"2 : Coloration BackTrack"<<endl;
    cout<<"3 : Quitter"<<endl;
    int command;cin>>command;
    if (command == 0){
            clock_t debut = clock();
            cout<<"Coloration en cours ..."<<endl;
            g->coloration_sequentielle();
            clock_t fin = clock();
            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete colore en "<<temps<<" ms"<<endl;
            cout<<"Lancement de la verification ..."<<endl;
            cout<<"La coloration a ete effectue avec "<<g->nombreCouleur()<<" couleur "<<endl;
            if (g->grapheBienColore()) cout<<"Le graphe a ete correctement colore"<<endl;
            else cout<<"Erreur dans la coloration"<<endl;

    }
    else if (command == 1){
         clock_t debut = clock();
            cout<<"Coloration en cours ..."<<endl;
            g->coloration_minimal();
            clock_t fin = clock();
            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete colore en "<<temps<<" ms"<<endl;
            cout<<"Lancement de la verification ..."<<endl;
            cout<<"La coloration a ete effectue avec "<<g->nombreCouleur()<<" couleur"<<endl;
            if (g->grapheBienColore()) cout<<"Le graphe a ete correctement colore"<<endl;
            else cout<<"Erreur dans la coloration"<<endl;
    }
    else if (command == 2){
         clock_t debut = clock();
            cout<<"Coloration en cours ..."<<endl;
            g->coloration_back_track();
            clock_t fin = clock();
            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete colore en "<<temps<<" ms"<<endl;
            cout<<"Lancement de la verification ..."<<endl;
            cout<<"La coloration a ete effectue avec "<<g->nombreCouleur()<<"couleur "<<endl;
            if (g->grapheBienColore()) cout<<"Le graphe a ete correctement colore"<<endl;
            else cout<<"Erreur dans la coloration"<<endl;
    }
    else if (command == 3){return 0;}

}




}
int main(int argc, char *argv[])
{
    int command;
    system("clear");
    cout<<"Projet Coloration Graphe\n"<<endl;
    cout<<"0 : mode graphique"<<endl;
    cout<<"1 : mode console"<<endl;
    cin>>command;
    system("clear");


    if (command == 0){
        QApplication a(argc, argv);
        MainWindow *win = new MainWindow();
        win->show();
        return a.exec();
    }
    else{
        Biparti * g = new Biparti();

        cout<<"0 : generation 1 "<<endl;
        cout<<"1 : generation inverse"<<endl;
        cout<<"2 : generation biparti complet "<<endl;
        cin>>command;
        if (command == 0){
            int delta;int nb;
            cout<<"Entrez le nombre de sommet héhé : ";cin>>nb;
            cout<<"Entrez le delta maximum : ";cin>>delta;cout<<endl;
            clock_t debut = clock();
            cout<<"Generation en cours ..."<<endl;
            g->generer2(nb,delta);
            clock_t fin = clock();

            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete cree en "<<temps<<" ms"<<endl;
            cout<<"Delta : "<<g->getDelta()<<endl;
            cout<<"Aretes : "<<g->getM()<<endl;
            coloration(g);


        }
        else if ( command == 1){
             int delta;int nb;
            cout<<"Entrez le nombre de sommet : ";cin>>nb;
            cout<<"Entrez le delta maximum : ";cin>>delta;cout<<endl;
            clock_t debut = clock();
            cout<<"Generation en cours ..."<<endl;
            g->generer(nb,delta);
            clock_t fin = clock();
            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete cree en "<<temps<<" ms"<<endl;
            cout<<"Delta : "<<g->getDelta()<<endl;
            cout<<"Aretes : "<<g->getM()<<endl;
            coloration(g);
        }
        else if (command == 2){
            int nb;
            cout<<"Entrez le nombre de sommet : ";cin>>nb;
            cout<<"Generation en cours ..."<<endl;
            cout<<endl;
            clock_t debut = clock();
            g->generer_graphe_complet(nb);
            clock_t fin = clock();
            cout<<endl;
            double temps = (double)((fin - debut)/1000);
            cout<<"Le graphe a ete cree en "<<temps<<" ms"<<endl;
            cout<<"Delta : "<<g->getDelta()<<endl;
            cout<<"Aretes : "<<g->getM()<<endl;
            coloration(g);


        }

    }
}
